package ldh.im.fxgui.pojo;

import javafx.beans.property.*;
import ldh.im.fxbase.cache.SoftId;
import ldh.im.fxbase.pojo.ext.UserType;

import java.time.LocalDateTime;

public class MItem implements SoftId {

    private IntegerProperty newMessageCount = new SimpleIntegerProperty(0);   // 新消息个数
    private StringProperty name = new SimpleStringProperty("");               // 名称
    private ObjectProperty<LocalDateTime> createDate = new SimpleObjectProperty<>();                   // 创建时间
    private StringProperty newMessage = new SimpleStringProperty("");         // 最新消息
    private ObjectProperty<UserType> userType = new SimpleObjectProperty<>(UserType.User);      // 消息群
    private ObjectProperty<LocalDateTime> newMessageDate = new SimpleObjectProperty<>();  // 最新消息的时间
    private boolean isTop = false;

    public int getNewMessageCount() {
        return newMessageCount.get();
    }

    public IntegerProperty newMessageCountProperty() {
        return newMessageCount;
    }

    public void setNewMessageCount(int newMessageCount) {
        this.newMessageCount.set(newMessageCount);
    }

    public String getName() {
        return name.get();
    }

    public StringProperty nameProperty() {
        return name;
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public String getNewMessage() {
        return newMessage.get();
    }

    public StringProperty newMessageProperty() {
        return newMessage;
    }

    public void setNewMessage(String newMessage) {
        this.newMessage.set(newMessage);
    }

    public UserType getUserType() {
        return userType.get();
    }

    public ObjectProperty<UserType> userTypeProperty() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType.set(userType);
    }

    public LocalDateTime getCreateDate() {
        return createDate.get();
    }

    public ObjectProperty<LocalDateTime> createDateProperty() {
        return createDate;
    }

    public void setCreateDate(LocalDateTime createDate) {
        this.createDate.set(createDate);
    }

    public LocalDateTime getNewMessageDate() {
        return newMessageDate.get();
    }

    public ObjectProperty<LocalDateTime> newMessageDateProperty() {
        return newMessageDate;
    }

    public void setNewMessageDate(LocalDateTime newMessageDate) {
        this.newMessageDate.set(newMessageDate);
    }

    @Override
    public String getSoftId() {
        return name.get();
    }

    public boolean isTop() {
        return isTop;
    }

    public void setTop(boolean top) {
        isTop = top;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (!(obj instanceof MItem)) return false;
        MItem d = (MItem) obj;
        return d.getSoftId().equals(this.getSoftId());
    }

    @Override
    public int hashCode() {
        return this.getSoftId().hashCode();
    }
}
